package controller.register;

import controller.login.*;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author HTTHANH
 */
@FacesValidator("TDNvalidator")
public class TDNValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String TDN = value.toString();
      /*   CheckRegister.tendangnhap = TDN;
        UIInput uiInputhoten = (UIInput) component.getAttributes().get("hoten");
        CheckRegister.hoten = uiInputhoten.getSubmittedValue().toString();
       
         UIInput uiInputnoisong = (UIInput) component.getAttributes().get("noisong");         
        CheckRegister.noisong = uiInputnoisong.getSubmittedValue().toString();
        
        UIInput uiInputngay = (UIInput) component.getAttributes().get("ngay");
        CheckRegister.ngaysinh = Integer.parseInt(uiInputngay.getSubmittedValue().toString());

        UIInput uiInputthang = (UIInput) component.getAttributes().get("thang");
        CheckRegister.thangsinh = Integer.parseInt(uiInputthang.getSubmittedValue().toString());
        UIInput uiInputnam = (UIInput) component.getAttributes().get("nam");
        CheckRegister.namsinh = Integer.parseInt(uiInputnam.getSubmittedValue().toString());
*/


        // Let required="true" do its job.
        if (TDN == null || TDN.isEmpty()) {
            return;
        }

        if (!CheckRegister.checkTDN(TDN)) {
            throw new ValidatorException(new FacesMessage(
                    "TDN bị trùng."));
        }

    }
}
